package com.qeng.aiwanba.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.qeng.aiwanba.util.DebugFlag;
import com.qeng.aiwanba.util.MyWxApiManager;
import com.qeng.aiwanba.util.PayUtil;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;


/**
 * Created by lixy on 17/3/13.
 */

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        handleIntent(getIntent());
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        handleIntent(intent);
    }

    private void handleIntent(Intent intent) {
        MyWxApiManager.getInstance().getIwxapi(this).handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {
    }

    @Override
    public void onResp(BaseResp resp) {
        DebugFlag.logDebug("TAG", "onPayFinish, errCode =" +resp.errCode);
        if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            PayUtil.getJsCallback().onCallBack(String.valueOf(resp.errCode));
        }

        this.finish();
    }
}
